<template>
  <view class="">
    <cu-custom bgColor="bg-gradual-green" :isBack="true">
      <block slot="backText">返回</block>
      <block slot="content">备课计划</block>
    </cu-custom>

    <view style="width: 100%;position: relative;">
      <image style="width: 100%;height: 260upx;" src="../../static/37.png" mode=""></image>
      <view style="position: absolute;top: 100upx;width: 100%;text-align: center;">
        <view style="color: #fff;">
          添加备课计划,可以更好地定制适合您的训练
        </view>
        <view @click="jump" data-src='/pagesA/Preparation_plan/Add_course' style="color: #fff;background-color: #408CE2;width: 40%;height: 60upx;line-height: 60upx;border-radius: 30upx;margin-left: 30%;margin-top: 30upx;font-size: 22upx;">
          + 添加备课计划
        </view>
      </view>
    </view>


    <uni-swipe-action>
      <uni-swipe-action-item v-for="(item,index) in list" :options="item.options" :key="item.id" @change="swipeChange"
        @click="swipeClick($event, item.id)">
        <view @click="jump($event, item)" :data-src='"/pagesA/Preparation_plan/curriculum?id="+item.id' style="width: 100%;background-color: #fff;padding: 20upx;">
          <view style="height: 50upx; font-size: 26rpx;" class="u-f-ac">
            <view>{{item.name}}</view>
            <view class="course-name">{{item.courseTypeName}}</view>
          </view>
          <view style="height: 50upx;display: flex;justify-content: space-between;">
            <view style="font-size: 40rpx;font-weight: bold;">
              0/{{item.courseCount}}
            </view>
            <view style="font-size: 22upx;color: #666;">
              <text>{{item.teachName}}</text> <text style="margin-left: 30upx;">{{item.createTime}}</text>
            </view>
          </view>
          <view>
            <progress percent="0" active stroke-width="3" backgroundColor="#999" />
          </view>
        </view>
      </uni-swipe-action-item>
    </uni-swipe-action>



    <!-- <block v-for="(item, index) in list" :key="index">
			
		</block> -->
  </view>
</template>

<script>
  export default {
    data() {
      return {
        list: [],
        user: {},
      }
    },
    onLoad() {
      this.user = uni.getStorageSync("phyUser");
      this.getData(this.user.userId)
    },
    onShow() {
      this.getData(this.user.userId)
    },
    methods: {
      async getData(userId) {
        let {
          data: {
            datas
          }
        } = await this.$myRuquest({
          url: "/coach/training/getTrainingPlanList",
          data: {
            userId
          }
        })
        this.list = datas;
        let siwpers = {
          options: [{
            text: '删除',
            style: {
              backgroundColor: 'rgb(255,58,49)'
            }
          }],
          sid: 0,
          content: 'item1'
        }
        this.list.forEach((item, index) => {
          Object.assign(item, siwpers)
        })
      },

      swipeChange(e) {
        console.log('返回：', e);
      },
      swipeClick(e, id) {
        let {
          content
        } = e
        if (content.text === '删除') {
          uni.showModal({
            title: '提示',
            content: '是否删除',
            success: (res) => {
              console.log('用户点击了删除', res, id)
              this.deleteServer(id)
              if (res.confirm) {} else if (res.cancel) {
                console.log('用户点击取消');
              }
            }
          });
        }
      },
      async deleteServer(trainingPlanId) {
        uni.showLoading({
          title: "正在删除..."
        })
        let {
          data: {
            result
          }
        } = await this.$myRuquest({
          url: "/coach/training/deleteTrainingPlanById?trainingPlanId=" + trainingPlanId,
          method: "DELETE",
        })
        if (result == 200) {
          uni.showToast({
            title: '删除成功~',
            icon: "success",
            duration: 1000
          });
          this.getData(this.user.userId);
        }
        uni.hideLoading();
      },
      jump(e, item) {
        console.log(e.currentTarget.dataset.src)
        if (e.currentTarget.dataset.src.indexOf('curriculum') != -1) uni.setStorageSync("course", item);
        if (e.currentTarget.dataset.src == 'Not-yet-open') {
          uni.showModal({
            title: '提示',
            content: '功能即将开放',
            showCancel: false,
            confirmColor: "#DD524D",
            success() {
              return
            }
          })
        } else {
          uni.navigateTo({
            url: e.currentTarget.dataset.src
          });
        }
      },

    }
  }
</script>

<style lang="scss" scoped>
  page {
    background-color: #F8F8F8;
  }

  .course-name {
    background-color: #D7ECFB;
    color: #2C7BA8;
    margin-left: 20rpx;
    padding: 4rpx;
  }
</style>
